#!/usr/bin/env bash

__rvm_version_installed_when()
{
  \typeset installed_at years months days hours minutes seconds part

  installed_at="$(\command \cat ${rvm_path}/installed.at)"

  if
    [[ -n "${installed_at:-}" ]] && (( installed_at ))
  then
    seconds="$(( $(__rvm_date +%s) - installed_at ))"
    if
      (( seconds ))
    then
      minutes="$(( seconds / 60 % 60 ))"
      hours="$(( seconds / 3600 % 24 ))"
      days="$(( seconds / 86400 % 31 ))"
      months="$(( seconds / 2678400 % 12 ))"
      years="$(( seconds / 31536000 ))"
      seconds="$(( seconds % 60 ))"

      installed_at=""
      for part in year month day hour minute second
      do
        partvar="${part}s"
        (( ${!partvar} )) || continue
        installed_at="${installed_at}${!partvar} ${part}$( (( ${!partvar} == 1 )) || echo "s") "
      done
      installed_at="${installed_at}ago"
    else
      installed_at="just now"
    fi
  else
    installed_at="can not read installation time"
  fi

  echo ${installed_at}
}